# Makefile for SMART
#
# 06-12-2008; (c) Guoyong Shi
# 09-11-2008; Zhigang Hao

CC		= g++
#HOME	= /c/EDA/MOR/SMART
HOME	= .
#CPP_DIR = /c/cygwin
#INCLUDE	= ../inc
INCLUDE	= 
#BAKUP	= ../bak
#CPP_INC = -I$(CPP_DIR)/lib/gcc/i686-pc-cygwin/3.4.4/include/c++ 

#LIB		= $(CPP_DIR)/lib

PCCTS	= $(HOME)/pccts
ANTLR_H	= $(PCCTS)/h
BIN		= $(PCCTS)/bin
ANTLR	= $(BIN)/Antlr.exe
DLG		= $(BIN)/Dlg.exe

DEFINE	= -DTRACE -DDEBUG  
#DEFINE	= -DNTRACE -DDEBUG  
AFLAGS	= -CC
DFLAGS	= -C2 -i -CC
#CFLAGS	= -g -I. -I$(ANTLR_H) -I$(INCLUDE) $(CPP_INC) $(DEFINE) 
#CFLAGS	= -g $(DEFINE) -I. -I$(ANTLR_H) -I$(INCLUDE)
CFLAGS	= -g -I. -I$(ANTLR_H) -I$(INCLUDE)  $(DEFINE)
LFLAGS	= -O6 

TARGET	= SMARTr1000
# suffix 'r' indicates the "recursive' implementation

SRCS = \
       SmartMain.cpp \
       ToGraph.cpp \
       RDD.cpp \
       MOR.cpp \
       utility.cpp 

HEADERS = \
		  RDD.h MOR.h SmartGlobal.h RDDStruct.h \
          utility.h ToGraph.h stack.h

OBJS = $(SRCS:.cpp=.o) 

# Parser related source files:
SRCP = netgram.cpp netparser.cpp \
	   $(ANTLR_H)/AParser.cpp $(ANTLR_H)/ATokenBuffer.cpp \
	   $(ANTLR_H)/DLexerBase.cpp DLGLexer.cpp

# Parser related object files:
OBJP = netgram.o netparser.o \
	   AParser.o ATokenBuffer.o DLexerBase.o DLGLexer.o

.cpp.o:
	$(CC) $(CFLAGS) -c $<
.cc.o:
	$(CC) $(CFLAGS) -c $<

# Grammar file for pccts
GRM	= netgram.g		

# Files generated by "antlr":
ANTLR_SPAWN = netgram.cpp netparser.cpp netparser.h \
				tokens.h parser.dlg
DLG_SPAWN   = DLGLexer.cpp DLGLexer.h

all: $(TARGET) 

$(OBJS) : $(HEADERS) Makefile

$(TARGET) : $(OBJS) $(OBJP) 
	@echo -n Linking $(TARGET) ...
	@echo
	$(CC) $(LFLAGS) -o $@ $(OBJS) $(OBJP) -lm
	cp $(TARGET) ../.
	@echo [$(TARGET).exe] done

# <antlr> and <dlg> generate *.h and *.cpp files
$(ANTLR_SPAWN) : $(GRM)
	$(ANTLR) $(AFLAGS) $(GRM)
$(DLG_SPAWN) : parser.dlg
	$(DLG) $(DFLAGS) parser.dlg

netgram.o : tokens.h DLGLexer.h netgram.cpp Makefile
	$(CC) -c $(CFLAGS) -o $@ netgram.cpp
netparser.o : tokens.h DLGLexer.h netparser.cpp
	$(CC) -c $(CFLAGS) -o $@ netparser.cpp

# The following three dependencies are standard

AParser.o : $(ANTLR_H)/AParser.cpp
	$(CC) -c $(CFLAGS) -o AParser.o $(ANTLR_H)/AParser.cpp
ATokenBuffer.o : $(ANTLR_H)/ATokenBuffer.cpp
	$(CC) -c $(CFLAGS) -o ATokenBuffer.o $(ANTLR_H)/ATokenBuffer.cpp
DLexerBase.o : $(ANTLR_H)/DLexerBase.cpp
	$(CC) -c $(CFLAGS) -o DLexerBase.o $(ANTLR_H)/DLexerBase.cpp


clean:
	rm -f *.o
clear:
	rm -f *.ic0
	rm -f *.tr0
	rm -f *.st0

#backup:
#	cp $(SRCS) $(HEADERS) $(BAKUP)

